<template>
  <div>
    <div class="chart2" ref="Pillar" />
  </div>
</template>

<script>
import echarts from "echarts";
export default {
  name:'Pillar',
  data() {
    return {
      Pillar: null,
    };
  },
  methods: {
    initCharts() {
      if (this.Pillar) {
        // 销毁对象
        this.Pillar.dispose();
      }
      this.Pillar = echarts.init(this.$refs.Pillar, "light");
      var option2 = {
        tooltip: {},
        legend: {
          data: ["销量"],
        },
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
          },
        ],
      };
      this.Pillar.setOption(option2);
    },
  },
  mounted() {
    //挂载完成
    this.initCharts();
    window.addEventListener("resize", this.initCharts, false);
  },
  beforeDestroy() {
    // 销毁前
    window.removeEventListener("resize", this.initCharts, false);
  },
};
</script>

<style lang="scss" scoped>
.chart2 {
  width: 50%;
  height: 400px;
  margin-top: 30px;
  float: left;
}
</style>